package com.syezon.wifikey.msg;

import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;

import com.hodanet.appadvplatclient.ad.AdInfo;
import com.syezon.wifikey.R;
import com.syezon.wifikey.about.AboutActivity;
import com.syezon.wifikey.ad.AdPositionEnum;
import com.syezon.wifikey.ad.AdUtils;
import com.syezon.wifikey.base.BaseActivity;
import com.syezon.wifikey.msg.adapter.MsgAdapter;
import com.syezon.wifikey.msg.info.MsgInfo;
import com.syezon.wifikey.setting.GradeConfig;
import com.syezon.wifikey.splash.AgreementDialog;
import com.syezon.wifikey.utils.MarketUtils;
import com.syezon.wifikey.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MessageActivity extends BaseActivity implements MsgAdapter.MsgItemClickListener {

    @BindView(R.id.rl_top)
    RelativeLayout mRlTop;
    @BindView(R.id.rv_msg)
    RecyclerView mRvMsg;
    private MsgAdapter mMsgAdapter;
    private List<MsgInfo> mMsgAdList = new ArrayList<>();


    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_message;
    }

    @Override
    protected void initViewsAndEvents() {
        StatusBarUtil.setPaddingSmart(this, mRlTop);
        mRvMsg.setLayoutManager(new LinearLayoutManager(this));
        mMsgAdapter = new MsgAdapter(this);
        DividerItemDecoration divider = new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
        divider.setDrawable(getResources().getDrawable(R.drawable.bg_msg_divider));
        mRvMsg.addItemDecoration(divider);
        mRvMsg.setAdapter(mMsgAdapter);
        mMsgAdapter.setMsgItemClickListener(this);
        mMsgAdapter.setData(getDefaultMsgList());
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }
    }

    private List<MsgInfo> getDefaultMsgList() {
        List<MsgInfo> defaultMsgList = new ArrayList<>();
//        MsgInfo feedBackMsgInfo = new MsgInfo();
//        feedBackMsgInfo.setType(MsgInfo.TYPE_FEED_BACK);
//        feedBackMsgInfo.setResId(R.drawable.ic_feedback);
//        feedBackMsgInfo.setTitle("意见反馈");
//        feedBackMsgInfo.setOrder(MsgInfo.ORDER_FEED_BACK);
//        defaultMsgList.add(feedBackMsgInfo);
        MsgInfo aboutMsgInfo = new MsgInfo();
        aboutMsgInfo.setType(MsgInfo.TYPE_ABOUT);
        aboutMsgInfo.setResId(R.drawable.ic_about);
        aboutMsgInfo.setTitle("关于");
        aboutMsgInfo.setOrder(MsgInfo.ORDER_ABOUT);
        defaultMsgList.add(aboutMsgInfo);

        MsgInfo agreementMsgInfo = new MsgInfo();
        agreementMsgInfo.setType(MsgInfo.TYPE_AGREEMENT);
        agreementMsgInfo.setResId(R.drawable.ic_agreement);
        agreementMsgInfo.setTitle("用户协议");
        agreementMsgInfo.setOrder(MsgInfo.ORDER_AGREEMENT);
        defaultMsgList.add(agreementMsgInfo);

        MsgInfo privacyMsgInfo = new MsgInfo();
        privacyMsgInfo.setType(MsgInfo.TYPE_PRIVACY);
        privacyMsgInfo.setResId(R.drawable.ic_privacy);
        privacyMsgInfo.setTitle("隐私协议");
        privacyMsgInfo.setOrder(MsgInfo.ORDER_PRIVACY);
        defaultMsgList.add(privacyMsgInfo);

        if (GradeConfig.canJumpMarket()) {
            MsgInfo gradeMsgInfo = new MsgInfo();
            gradeMsgInfo.setType(MsgInfo.TYPE_GRADE);
            gradeMsgInfo.setResId(R.drawable.ic_grade_indicator);
            gradeMsgInfo.setTitle("评分鼓励");
            gradeMsgInfo.setOrder(MsgInfo.ORDER_GRADE);
            defaultMsgList.add(gradeMsgInfo);
        }
        return defaultMsgList;
    }

    @Override
    public void onSettingClick(MsgInfo msgInfo) {
        if (msgInfo.getType() == MsgInfo.TYPE_ABOUT) {
            readyGo(AboutActivity.class);
        }
        if (msgInfo.getType() == MsgInfo.TYPE_AGREEMENT) {
            AgreementDialog.Helper.showAgreement(mContext);
        }
        if (msgInfo.getType() == MsgInfo.TYPE_PRIVACY) {
            AgreementDialog.Helper.showPrivacy(mContext);
        }
        if (msgInfo.getType() == MsgInfo.TYPE_GRADE) {
            MarketUtils.launchAppDetail2(this);
        }
//        if (msgInfo.getType() == MsgInfo.TYPE_FEED_BACK) {
//            try {
//                FeedbackAPI.openFeedbackActivity();
//            } catch (Exception e) {
//
//            }
//        }
    }

    @Override
    public void onAdClick(AdInfo adInfo) {
        AdUtils.adClicked(this, adInfo, AdPositionEnum.FLOAT_HOME_BOTTOM);
    }
}
